package com.youdoneed.community.common.utils;

import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;

import com.youdoneed.community.forum.entity.Forummessage;

/**
 * 比较两个帖子的时间
 * @author lid
 *
 */
public class MessageComparator implements Comparator<Forummessage>{

	@Override
	public int compare(Forummessage msg1, Forummessage msg2) {
		if(null == msg1.getCreateDate()){
			return 1;
		}
		
		if(null == msg2.getCreateDate()){
			return -1;
		}
		int flag = msg2.getCreateDate().compareTo(msg1.getCreateDate());
		return flag;
	}

	/*public static void main(String args[]){
		MessageComparator comparator = new MessageComparator();
		
		Forummessage msg1 = new Forummessage();
		Forummessage msg2 = new Forummessage();
		Date date = new Date();
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date);
		cal1.set(2016, 1, 1);
		msg1.setCreateDate(cal1.getTime());
		
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(date);
		cal2.set(2015, 1, 1);
		
		msg2.setCreateDate(cal2.getTime());
		System.out.println(comparator.compare(msg1, msg2));
	}*/
}
